package com.ruoyi.project.system.domain;

import com.alipay.api.response.AlipayFundTransCommonQueryResponse;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.math.BigDecimal;

/**
 * 提现对象 sm_extract
 */
@Data
public class SmExtract extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    private String extractId;

    /**
     * 提现用户ID
     */
    @Excel(name = "提现用户ID")
    private Integer userId;

    /**
     * 收款方真实姓名
     */
    @Excel(name = "收款方真实姓名")
    private String alipayName;

    /**
     * 支付宝登录号
     */
    @Excel(name = "支付宝登录号")
    private String alipayAccount;

    /**
     * 提现金额
     */
    @Excel(name = "提现金额")
    private BigDecimal amount;

    /**
     * 转账订单号
     */
    @Excel(name = "转账订单号")
    private String orderId;

    /**
     * 转账单据状态
     */
    @Excel(name = "转账单据状态")
    private String status;

    /**
     * 订单支付时间
     */
    @Excel(name = "订单支付时间")
    private String transDate;

    /**
     * 资金流水号
     */
    @Excel(name = "资金流水号")
    private String payFundOrderId;

    public SmExtract() {
    }
    // 添加提现单
    public SmExtract(String extractId, Integer userId, String alipayName, String alipayAccount, BigDecimal amount) {
        this.extractId = extractId;
        this.userId = userId;
        this.alipayName = alipayName;
        this.alipayAccount = alipayAccount;
        this.amount = amount;
        this.status = "审批中";
    }

    // 转账成功更新
    public SmExtract(AlipayFundTransCommonQueryResponse transfer) {
        this.setRemark("");
        this.extractId = transfer.getOutBizNo();
        this.orderId = transfer.getOrderId();
        this.payFundOrderId = transfer.getPayFundOrderId();
        this.transDate = transfer.getPayDate();
        this.status = "已转账";
    }

    // 转账失败/刷新转账状态失败 更新
    public SmExtract(String extractId, String remark) {
        this.extractId = extractId;
        this.setRemark(remark);
        this.status = "失败";
    }

    // 刷新转账状态
    public SmExtract(AlipayFundTransToaccountTransferResponse transfer) {
        this.setRemark("");
        this.extractId = transfer.getOutBizNo();
        this.orderId = transfer.getOrderId();
//        this.payFundOrderId = transfer.getPayFundOrderId();
        this.transDate = transfer.getPayDate();
        this.status = "已转账";
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("extractId", getExtractId())
                .append("userId", getUserId())
                .append("alipayName", getAlipayName())
                .append("alipayAccount", getAlipayAccount())
                .append("amount", getAmount())
                .append("orderId", getOrderId())
                .append("status", getStatus())
                .append("transDate", getTransDate())
                .append("payFundOrderId", getPayFundOrderId())
                .append("updateTime", getUpdateTime())
                .append("createTime", getCreateTime())
                .append("remark", getRemark())
                .toString();
    }
}
